<template>
  <el-form ref="form" :model="form" label-width="80px">
    <el-form-item label="任务标题">
      <el-input v-model="form.name"></el-input>
    </el-form-item>
    <el-form-item label="抓取链接">
      <el-input type="textarea" v-model="form.links" :autosize="{ minRows: 8, maxRows: 18}"></el-input>
    </el-form-item>
    <el-form-item label="抓取规则">
      <el-input type="textarea" v-model="form.rule" :autosize="{ minRows: 18}"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">确定</el-button>
      <slot name="cancel"></slot>
    </el-form-item>
  </el-form>
</template>
<script>
import axios from 'axios'

export default {
  props: {
    form: {
      type: Object,
      default () {
        return {
          name: '',
          rule: '',
          links: ''
        }
      }
    }
  },
  data () {
    return {
    }
  },
  methods: {
    onSubmit () {
      let postData = {
        name: this.form.name,
        rule: JSON.parse(this.form.rule),
        links: this.form.links.split('\n')
      }
      let that = this
      axios.post('http://127.0.0.1:5000/task',
        postData
      ).then(function (resp) {
        that.$message({message: '保存成功', type: 'success'})
      }).catch(function (error) {
        console.log(error)
        that.$message.error('错了哦')
      })
    }
  }
}
</script>
